package com.edu.cuotibook.dao;

import com.edu.cuotibook.dao.mapper.ExamPaperDao;
import com.edu.cuotibook.entity.pojo.ExamPaper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ExamPaperDaoService{

    @Resource
    private ExamPaperDao examPaperDao;


    public int insertSelective(ExamPaper pojo){
        return examPaperDao.insertSelective(pojo);
    }

    public int insertList(List<ExamPaper> pojos){
        return examPaperDao.insertList(pojos);
    }

    public int update(ExamPaper pojo){
        return examPaperDao.update(pojo);
    }

    public void insertOrUpdate(ExamPaper paper) {

        List<ExamPaper> result = examPaperDao.select(paper);
        if (!CollectionUtils.isEmpty(result)) {
            paper.setId(result.get(0).getId());
            return;
        }
        examPaperDao.insertSelective(paper);
    }

    public ExamPaper selectById(Long paperId) {
        return examPaperDao.selectById(paperId);
    }

    public void initSql() {
        examPaperDao.initSql();
    }
}
